package com.ruoyi.optimization.service.impl;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.optimization.domain.OptimizationRecord;
import com.ruoyi.optimization.mapper.OptimizationRecordMapper;
import com.ruoyi.optimization.service.IOptimizationRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 优化记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-13
 */
@Service
public class OptimizationRecordServiceImpl implements IOptimizationRecordService 
{
    @Autowired
    private OptimizationRecordMapper optimizationRecordMapper;

    /**
     * 查询优化记录
     * 
     * @param id 优化记录主键
     * @return 优化记录
     */
    @Override
    @DataScope(userAlias = "u")
    public OptimizationRecord selectOptimizationRecordById(Long id)
    {
        OptimizationRecord optimizationRecord = new OptimizationRecord();
        optimizationRecord.setId( id);
        return optimizationRecordMapper.selectOptimizationRecordById(optimizationRecord);
    }

    /**
     * 查询优化记录列表
     * 
     * @param optimizationRecord 优化记录
     * @return 优化记录
     */
    @Override
    @DataScope(userAlias = "u")
    public List<OptimizationRecord> selectOptimizationRecordList(OptimizationRecord optimizationRecord)
    {
        return optimizationRecordMapper.selectOptimizationRecordList(optimizationRecord);
    }
    /**
     * 查询优化记录列表
     *
     * @param createBy 优化记录
     * @return 优化记录集合
     */
    @Override
    public List<OptimizationRecord> listOptimizationRecordBycreateBy(String createBy)
    {
        return optimizationRecordMapper.listOptimizationRecordBycreateBy(createBy);

    }
    /**
     * 新增优化记录
     *
     * @param optimizationRecord 优化记录
     * @return 结果
     */
    @Override
    public int insertOptimizationRecord(OptimizationRecord optimizationRecord,String authorization)
    {
        if (authorization != null && SecurityUtils.getLoginUser()!= null){
            optimizationRecord.setCreateTime(DateUtils.getNowDate());
            optimizationRecord.setCreateBy(SecurityUtils.getUsername());
            optimizationRecord.setCreateById(SecurityUtils.getUserId());
        }else{
            optimizationRecord.setCreateTime(DateUtils.getNowDate());
            optimizationRecord.setCreateBy("niming");
            optimizationRecord.setCreateById(0L);
        }

        return optimizationRecordMapper.insertOptimizationRecord(optimizationRecord);
    }
    /**
     * 新增优化记录
     * 
     * @param optimizationRecord 优化记录
     * @return 结果
     */
    @Override
    public int insertOptimizationRecord(OptimizationRecord optimizationRecord)
    {
        optimizationRecord.setCreateTime(DateUtils.getNowDate());
        optimizationRecord.setCreateBy(SecurityUtils.getUsername());
        optimizationRecord.setCreateById(SecurityUtils.getUserId());
        return optimizationRecordMapper.insertOptimizationRecord(optimizationRecord);
    }

    /**
     * 修改优化记录
     * 
     * @param optimizationRecord 优化记录
     * @return 结果
     */
    @Override
    public int updateOptimizationRecord(OptimizationRecord optimizationRecord)
    {
        optimizationRecord.setUpdateTime(DateUtils.getNowDate());
        optimizationRecord.setUpdateBy(SecurityUtils.getUsername());
        optimizationRecord.setUpdateById(SecurityUtils.getUserId());
        return optimizationRecordMapper.updateOptimizationRecord(optimizationRecord);
    }

    /**
     * 批量删除优化记录
     * 
     * @param ids 需要删除的优化记录主键
     * @return 结果
     */
    @Override
    public int deleteOptimizationRecordByIds(Long[] ids)
    {
        return optimizationRecordMapper.deleteOptimizationRecordByIds(ids);
    }

    /**
     * 删除优化记录信息
     * 
     * @param id 优化记录主键
     * @return 结果
     */
    @Override
    public int deleteOptimizationRecordById(Long id)
    {
        return optimizationRecordMapper.deleteOptimizationRecordById(id);
    }
}
